import 'package:flutter/material.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/page/login/area_widget/area_item.dart';
import 'package:full_display/page/login/area_widget/area_provider.dart';
import 'package:full_display/unit/asset_utils/asset_utils.dart';
import 'package:full_display/unit/navigation/navigation_util.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:full_display/unit/toast/toast_util.dart';
import 'package:provider/provider.dart';

class AreaCodeWidget extends StatelessWidget {
  const AreaCodeWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (_) => AreaProvider(),
        )
      ],
      child: const AreaCodePage(),
    );
  }
}

class AreaCodePage extends StatefulWidget {

  const AreaCodePage({super.key});

  @override
  State<AreaCodePage> createState() {
    return _AreaCodeWidgetState();
  }
}

class _AreaCodeWidgetState extends State<AreaCodePage> {

  var _areaProvider = AreaProvider();

  @override
  Widget build(BuildContext context) {
    _areaProvider = context.watch<AreaProvider>();
    return Scaffold(
      backgroundColor: ColorPlate.background,
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          '选择国家和地区',
          style: StandardTextStyle.textWhite16Style,
        ),
        shadowColor: ColorPlate.transparent,
        backgroundColor: ColorPlate.background,
        leading: GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            // NavigationUtil.getInstance().pop({'key': 'value'});
          },
          child: SizedBox(
            width: 20.0.W,
            height: 20.0.H,
            child: const Icon(
              Icons.arrow_back_ios_outlined,
              size: 24,
              color: ColorPlate.white,
            ),
          ),
        ),
        actions: [
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              showToast('搜索');
            },
            child: Container(
              margin: EdgeInsets.only(right: 15.0.W),
              width: 20.0.W,
              height: 20.0.H,
              child: Image.asset(AssetUtils.getAssetImage('icon_search')),
            ),
          )
        ],
      ),
      body: ListView.builder(
          itemCount: AreaProvider.areaCode.length,
          itemBuilder: (con, index) {
            return AreaItem(
              title: AreaProvider.areaCode[index],
              code: AreaProvider.areaCode[index],
              itemClick: () {
                NavigationUtil.getInstance().pop({'key': AreaProvider.areaCode[index]});
              },
            );
          }),
    );
  }
}
